package pseudoAssemblerCompiler.twopassassembler.view.util;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.MessageBox;

import java.util.ArrayList;
import java.util.List;

/**
 * User: Роман
 * Date: 21.05.12
 * Time: 18:24
 */
public class CTabFolderContainer {

    /**
     * Панель
     */
    private CTabFolder _cTabFolder;

    public CTabFolder get_cTabFolder() {
        return _cTabFolder;
    }

    public void set_cTabFolder(CTabFolder _cTabFolder) {
        this._cTabFolder = _cTabFolder;
    }

    public List<CTabItem> getTabItems() {
        return _tabItems;
    }

    public void setTabItems(List<CTabItem> tabItems) {
        this._tabItems = tabItems;
    }

    /**
     * Вкладки
     */
    private List<CTabItem> _tabItems = new ArrayList<CTabItem>();

    public CTabFolderContainer(Composite aParent) {
        _cTabFolder = new CTabFolder(aParent, SWT.BORDER | SWT.CLOSE);
        _cTabFolder.setSimple(false);
        _cTabFolder.setUnselectedImageVisible(false);
        _cTabFolder.setUnselectedCloseVisible(false);
        layouts();
    }

    public Composite createCTabItem(String tabItemName) {
        Composite composite = new Composite(get_cTabFolder(), SWT.NONE);

        FormData formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        composite.setLayout(new FormLayout());
        composite.setLayoutData(formData);

        CTabItem newCTabItem = new CTabItem(get_cTabFolder(), SWT.NONE);
        newCTabItem.setText(tabItemName);
        newCTabItem.setControl(composite);
        get_cTabFolder().setSelection(newCTabItem); //выбрали вкладку по умолчанию
        _tabItems.add(newCTabItem);
        return composite;
    }

    private void listeners() {
        // Add a listener to get the close button on each tab

    }

    private void layouts() {
        FormData formData;
        //Атрибуты
        formData = new FormData();
        formData.left = new FormAttachment(0, 0);
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        _cTabFolder.setLayoutData(formData);
    }

}
